% function dGemricGraphs(basedir,serie,slice)

% The estimated parameters are saved in a parameters.mat:
% parameters[parameter,serie,prot,masknr,mask] with parameter code:
% 1: meanT1 2:medianT1 3:stdT1 4:weightedmeanT1
% 5:weightedSqMeanT1 6:medianCR

basedir = 'C:\Users\Henk Smit\Desktop\MRData\120322dGemricQmap';

protocols = 2;
cd(basedir)
% cd('C:\Users\Henk Smit\Desktop\MRData\110926 Jasper 10 dGe Volunteers\LocPar1-4(1-4)5-20(1,2)')
load('Estimated_parameters.mat')

%T1s read in all
% T1s(:,1) = reshape(squeeze(parameters(4,:,1,:,:)),prod(size(squeeze(parameters(4,:,1,:,:)))),1);
% T1s(:,2) = reshape(squeeze(parameters(4,:,2,:,:)),prod(size(squeeze(parameters(4,:,2,:,:)))),1);
% T1CRs(:,1) = reshape(squeeze(parameters(6,:,1,:,:)),prod(size(squeeze(parameters(6,:,1,:,:)))),1);
% T1CRs(:,2) = reshape(squeeze(parameters(6,:,2,:,:)),prod(size(squeeze(parameters(6,:,2,:,:)))),1);
% T1STDs(:,1) = reshape(squeeze(parameters(3,:,1,:,:)),prod(size(squeeze(parameters(6,:,1,:,:)))),1);
% T1STDs(:,2) = reshape(squeeze(parameters(3,:,2,:,:)),prod(size(squeeze(parameters(6,:,2,:,:)))),1);
% T1s(:,3) = reshape(squeeze(parameters(4,:,3,:,:)),prod(size(squeeze(parameters(4,:,3,:,:)))),1);
% T1s(:,4) = reshape(squeeze(parameters(4,:,4,:,:)),prod(size(squeeze(parameters(4,:,4,:,:)))),1);

%T1s read in per mask
T1sMask1(:,1) = reshape(squeeze(parameters(4,:,1,:,1)),40,1);
T1sMask2(:,1) = reshape(squeeze(parameters(4,:,1,:,2)),40,1);
T1sMask3(:,1) = reshape(squeeze(parameters(4,:,1,:,3)),40,1);
T1sMask1(:,2) = reshape(squeeze(parameters(4,:,2,:,1)),40,1);
T1sMask2(:,2) = reshape(squeeze(parameters(4,:,2,:,2)),40,1);
T1sMask3(:,2) = reshape(squeeze(parameters(4,:,2,:,3)),40,1);

%T1s read in scan 1/2
T1sScan1(:,1) = reshape(squeeze(parameters(2,1:2:19,1,:,:)),60,1);
T1sScan2(:,1) = reshape(squeeze(parameters(2,2:2:20,1,:,:)),60,1);
T1sScan1(:,2) = reshape(squeeze(parameters(2,1:2:19,2,:,:)),60,1);
T1sScan2(:,2) = reshape(squeeze(parameters(2,2:2:20,2,:,:)),60,1);
T1sScanNoarc = reshape(squeeze(parameters(2,1:4,2,:,:)),24,1);
T1sScanHires = reshape(squeeze(parameters(2,1:4,4,:,:)),24,1);
T1sScanArcxx = reshape(squeeze(parameters(2,1:4,3,:,:)),24,1);

%T1s read in scan 1/2 mask 1/2/3
T1sScan11(:,1) = reshape(squeeze(parameters(2,1:2:19,1,:,1)),20,1);
T1sScan21(:,1) = reshape(squeeze(parameters(2,2:2:20,1,:,1)),20,1);
T1sScan11(:,2) = reshape(squeeze(parameters(2,1:2:19,2,:,1)),20,1);
T1sScan21(:,2) = reshape(squeeze(parameters(2,2:2:20,2,:,1)),20,1);
T1sScan12(:,1) = reshape(squeeze(parameters(2,1:2:19,1,:,2)),20,1);
T1sScan22(:,1) = reshape(squeeze(parameters(2,2:2:20,1,:,2)),20,1);
T1sScan12(:,2) = reshape(squeeze(parameters(2,1:2:19,2,:,2)),20,1);
T1sScan22(:,2) = reshape(squeeze(parameters(2,2:2:20,2,:,2)),20,1);
T1sScan13(:,1) = reshape(squeeze(parameters(2,1:2:19,1,:,3)),20,1);
T1sScan23(:,1) = reshape(squeeze(parameters(2,2:2:20,1,:,3)),20,1);
T1sScan13(:,2) = reshape(squeeze(parameters(2,1:2:19,2,:,3)),20,1);
T1sScan23(:,2) = reshape(squeeze(parameters(2,2:2:20,2,:,3)),20,1);

%T1s read in per protocol
T1sSPGR1 = nonzeros(squeeze(parameters(4,:,1,:,1)));
T1sSPGR2 = nonzeros(squeeze(parameters(4,:,1,:,2)));
T1sSPGR3 = nonzeros(squeeze(parameters(4,:,1,:,3)));
T1sQMAP1 = nonzeros(squeeze(parameters(4,:,2,:,1)));
T1sQMAP2 = nonzeros(squeeze(parameters(4,:,2,:,2)));
T1sQMAP3 = nonzeros(squeeze(parameters(4,:,2,:,3)));

scatter(T1sQMAP3,T1sSPGR3,'*b')
hold on
scatter(T1sQMAP2,T1sSPGR2,'*r')
scatter(T1sQMAP1,T1sSPGR1,'*k')
axis([0 1000 0 1000]);
plot(1:1000,1:1000)

screensize = get(0,'Screensize');

figure('Name','SPGR vs (1)QMAP ARC, (2)QMAP NO-ARC, (3)QMAP Hi Res','Position', [0.02*screensize(3),0.1*screensize(4),0.95*screensize(3),0.6*screensize(4)]);
for i=1:2
    subplot(1,3,i)
    scatter(T1s(:,1),T1s(:,2),'.k')
    title(['SPGR vs QMAP NO ARC ' num2str(i)])
    hold on
    plot(1:1800,1:1800)
    axis([0 1800 0 1800])   
    hold on
end;

%scatter hires vs no arc
scatter(T1sScanNoarc(:),T1sScanHires(:),'*')
hold on
scatter(T1sScanNoarc(:),T1sScanArcxx(:),'.')
hold on
xlabel('MSIR-FSE')
ylabel('MSIR-ARC and MSIR-HiRes')
plot(1:1800,1:1800)
axis([0 1500 0 1500])



%scatter all means with color coded masks
figure('Position', [0.02*screensize(3),0.02*screensize(4),0.5*screensize(3),0.85*screensize(4)]);
scatter(T1sMask1(:,1),T1sMask1(:,2),'+k')
hold on
scatter(T1sMask2(:,1),T1sMask2(:,2),'*b')
hold on
scatter(T1sMask3(:,1),T1sMask3(:,2),'xr')
hold on
xlabel('SPGR')
ylabel('QMAP')
plot(1:1800,1:1800)
axis([0 1200 0 1200])
legend('femural weight bearing','femural posterior', 'tibial','Location','NorthWest')
title(['All series, different masks '])

%scatter all means with errorbars
figure('Position', [0.02*screensize(3),0.02*screensize(4),0.5*screensize(3),0.85*screensize(4)]);
errorbarxy(T1s(:,1),T1s(:,2),T1CRs(:,1),T1CRs(:,2),[],[],'w')
hold on
scatter(T1s(:,1),T1s(:,2),'.k')
xlabel('SPGR')
ylabel('QMAP')
plot(1:1800,1:1800)
axis([0 1800 0 1800])
title(['All series, errorbars '])

%scatter scan 1 vs scan 2
figure('Position', [0.02*screensize(3),0.02*screensize(4),0.5*screensize(3),0.85*screensize(4)]);
scatter(T1sScan1(:,1),T1sScan2(:,1),'.k')
hold on
scatter(T1sScan1(:,2),T1sScan2(:,2),'*r')
xlabel('Scan 1')
ylabel('Scan 2')
legend('SPGR','QMAP NO ARC','Location','NorthWest')
hold on
plot(1:1800,1:1800)
axis([0 2000 0 2000])
title(['Scan 1 vs Scan 2 '])

%scatter scan 1 vs scan 2 with patient colors
figure('Position', [0.02*screensize(3),0.02*screensize(4),0.5*screensize(3),0.85*screensize(4)]);
for(j=1:60)
    scatter(T1sScan1(j,1),T1sScan2(j,1),'.')
    hold on
    scatter(T1sScan1(j,2),T1sScan2(j,2),'*')
    if j==1
        legend('SPGR','QMAP NO ARC','Location','NorthWest')
    end      
end
hold on
xlabel('Scan 1')
ylabel('Scan 2')
hold on
plot(1:1800,1:1800)
axis([0 1800 0 1800])
title(['Scan 1 vs Scan 2, 10 patient colors '])

%scatter scan 1 vs scan 2 with mask colors
figure('Position', [0.02*screensize(3),0.02*screensize(4),0.5*screensize(3),0.85*screensize(4)]);
for(j=1:20)
    scatter(T1sScan11(j,1),T1sScan21(j,1),'.','MarkerEdgeColor',[0 0 1])
    hold on
    scatter(T1sScan12(j,1),T1sScan22(j,1),'.','MarkerEdgeColor',[0 1 1])
    scatter(T1sScan13(j,1),T1sScan23(j,1),'.','MarkerEdgeColor',[1 0 0]) 
    scatter(T1sScan11(j,2),T1sScan21(j,2),'*','MarkerEdgeColor',[0 0 1])
    scatter(T1sScan12(j,2),T1sScan22(j,2),'*','MarkerEdgeColor',[0 1 1])
    scatter(T1sScan13(j,2),T1sScan23(j,2),'*','MarkerEdgeColor',[1 0 0])
    legend('SPGR FemWB','SPGR FemPost','SPGR Tibial','QMAP FemWB','QMAP FemPost','QMAP Tibial','Location','NorthWest')
    hold on
end
hold on
xlabel('Scan 1')
ylabel('Scan 2')
hold on
plot(1:1800,1:1800)
axis([0 1800 0 1800])
title(['Scan 1 vs Scan 2 '])

%plot values in graph with errors
figure('Name','weighted mean T1s on 4 protocols, 3 masks');
subplot(3,1,1)
errorbar(1.01:1:20.01,T1s(1:20,1),T1CRs(1:20,1));
hold on
errorbar(1:20,T1s(50:69,1),T1STDs(50:69,1),'r');
title('Femur WB,')
subplot(3,1,2)
errorbar(1:4,T1s(:,2),Errs(:,1));
title('Femur Post,')
subplot(3,1,3)
errorbar(1:4,T1s(:,3),Errs(:,1));
title('Plateau WB,')
xlabel('1: McKinsey, 2: Qmap Arc, 3: Qmap no arc, 4: Qmap HiRes')


sc(McK(i).mask,[0,1],gray,sc(mr,[min(mr(:)),max(mr(:))],gray),McK(i).mask==0)



